#define FREQ  50

#define CHANNEL  0
#define RESOLVTION   8
#define SERVO   21


int calculatePWM(int degree)
{
  int min_width = 0.5/20*pow(2,RESOLVTION);
  int max_width = 2.5/20*pow(2,RESOLVTION);
  return ((max_width-min_width)*degree/180+min_width);
}


void setup()
{
  ledcSetup(CHANNEL,FREQ,RESOLVTION);
  ledcAttachPin(SERVO,CHANNEL);

}

void loop()
{
  for(int i = 0;i<=180;i+=10)
  {
    ledcWrite(CHANNEL,calculatePWM(i));
    delay(100);
  }
}
